package lambdasinaction.chap5;
import lambdasinaction.chap4.*;

import java.util.stream.*;
import java.util.*;

import static lambdasinaction.chap4.Dish.menu;

public class Reducing{

    public static void main(String...args){

        List<Integer> numbers = Arrays.asList(3,4,5,1,2);
        Integer reduce = numbers.stream().reduce(0, (a, b) -> a + b);
        System.out.println(reduce);

        Integer sum = numbers.stream().reduce(0, Integer::sum);
        System.out.println(sum);

        Integer min = numbers.stream().min(Integer::compare).get();
        System.out.println(min);

        Integer sumMenu = menu.stream().map(Dish::getCalories)
                .reduce(0, Integer::sum);
        System.out.println(sumMenu);
    }
}
